import 'package:flutter/material.dart';
import 'package:interview/components/app/app_text_button.dart';
import 'package:interview/theme/app_colors.dart';

class PageScreenHalf {
  // 默认按钮集合
  static List<Widget> _defaultButtons(BuildContext context) {
    return [
      AppTextButton(
        text: '取消',
        textColor: Colors.orange,
        backgroundColor:Colors.grey[100] ,
        onPressed: () => Navigator.pop(context, false),
      ),
      const SizedBox(height: 4.0), // 按钮之间的间距
      AppTextButton(
        text: '确定',
        backgroundColor:Colors.grey[200] ,
        textColor:  Colors.black87,
        onPressed: () => Navigator.pop(context, true),
      )
    ];
  }
  static Future<bool?> showHalfScreenModal(
    BuildContext context, {
    required Widget content, // 动态内容，外部传递
    bool showButtons = true, // 是否显示底部按钮，外部传递
    List<Widget>? buttons, // 底部按钮集合，支持自定义
    bool dismissible = true, // 点击蒙层是否支持关闭
  }) {
    final theme = Theme.of(context).extension<AppColors>()!;

    return showModalBottomSheet<bool>(
      context: context,
      isScrollControlled: true,
      backgroundColor: Colors.transparent,
      isDismissible: dismissible,// 是否允许点击蒙层关闭
      enableDrag: dismissible, // 是否允许拖拽关闭
      builder: (BuildContext context) {
        return DraggableScrollableSheet(
          initialChildSize: 0.5,
          minChildSize: 0.5,
          maxChildSize: 0.95,
          expand: false, // 避免强制展开，提升性能
          snap: true, // 启用吸附动画效果
          snapSizes: const [0.5, 0.95], // 吸附在 70% 和 100% 位置
          
          builder: (context, scrollController) {
            return Container(
              decoration: BoxDecoration(
                color: theme.subjectMix1,
                borderRadius: const BorderRadius.vertical(
                  top: Radius.circular(16.0),
                ),
              ),
              child: Column(
                children: [
                  Container(
                    width: 40.0,
                    height: 4.0,
                    margin: const EdgeInsets.symmetric(vertical: 8.0),
                    decoration: BoxDecoration(
                      color: Colors.grey[300],
                      borderRadius: BorderRadius.circular(2.0),
                    ),
                  ),
                  // 中间内容
                  Expanded(child: content),
                  // 可滚动内容
                  // Expanded(
                  //   child: SingleChildScrollView(
                  //     controller: scrollController, // 绑定滚动控制器
                  //     child: Column(
                  //       crossAxisAlignment: CrossAxisAlignment.start,
                  //       children: [content], // 动态注入子组件
                  //     ),
                  //   ),
                  // ),
                  // 底部按钮
                  if (showButtons)
                    Container(
                      padding: const EdgeInsets.symmetric(horizontal: 32.0, vertical:0.0,),
                      margin: const EdgeInsets.only(bottom: 20),
                      child: Column(
                        mainAxisAlignment: MainAxisAlignment.center,
                        children: buttons ??
                        _defaultButtons(context).expand((widget) {
                          return widget is SizedBox  ? [widget] : [widget, const SizedBox(height: 4.0)];
                        }).toList(),
                      ),
                    ),
                ],
              ),
            );
          },
        );
      },
    );
  }
}


